<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <!--<th:block th:include="include :: bootstrap-select-css"/>-->
    <!--<th:block th:include="include :: jasny-bootstrap-css"/>-->
    <!--<th:block th:include="include :: datetimepicker-css"/>-->
    <link th:href="@{/ruoyi/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/jquery-confirm.min.css}" rel="stylesheet"/>
</head>
<style type="text/css">

    @media screen and (max-width: 768px) {

    }

    /**电脑屏幕下显示***/
    @media screen and (min-width: 768px) {
        body {
            /*text-align:center;*/
            margin: 0px auto;
        }
        .dawenh{
            margin-left: -20px;width: 110%;
        }
        .qbinput{
            margin-left: -20px;width: 73%;float: right;
        }
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="operlog-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>检索：</label><input type="text" name="sbbh" id="sbbh" placeholder="请输入设备编码进行查询"
                                                       onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;$.alert('请点击后面的搜索框','温馨提示');}"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" id="search_btn"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div style="display: none" class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" id="delbfbs" onclick="addgsmc()">
                <i class="fa fa-pencil"></i> 维护分类
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div><input type="hidden" id="_pageNumber"></div>
<div><input type="hidden" id="_pageSize"></div>
<p id="ddh_p" style="display: none"></p>
<p id="djlx_p" style="display: none"></p>
<p id="id_p" style="display: none"></p>
<p id="pusername" style="display: none">[[${session.username}]]</p>
<p id="pgsid" style="display: none">[[${session.gsid}]]</p>
<th:block th:include="include :: footer"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:inline="javascript">
    // var sessionname = [[${session.username}]]
    // var gsid = [[${session.gsid}]]
    $(document).ready(function () {
        // $("#dengmz").val(sessionname)
        // if (gsid == null) {
        //     alert("当前状态未登陆系统或浏览器中当前会话结束了，您需要重新登陆")
        //     window.location.href = "/login";
        // }
        // $("#gsids").val(gsid)
        initUserTable();

        function initUserTable() {
            $("#bootstrap-table").bootstrapTable({
                toolbar: '#toolbar',
                showToggle: true,//是否切换显示
                showColumns: true,//是否显示列，
                showColumnsToggleAll: true,
                // detailView: true,//和下面的属性成对设置，是否显示加号显示详细信息
                // detailFormatter: "detailFormatter",
                showExport: true,//是否导出
                // showPaginationSwitch: true,//切换是否分页显示
                showFooter: true,//是否显示页脚，主要用途是显示汇总的信息
                striped: false,//是否显示行间隔色
                paginationPreText: '上一页',
                paginationNextText: '下一页',
                queryParamsType: '',
                method: 'GET',
                uniqueId: "id",
                exportDataType: "basic", //basic', 'all', 'selected'.
                // exportTypes:['Excel'],  //导出文件类型
                pageNumber: 'form' ? 1 : parseInt($('#_pageNumber').val()),
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 'form' ? 10 : parseInt($('#_pageSize').val()),//单页记录数
                pageList: [10, 20, 30, 'ALL'],//可选择单页记录数
                showRefresh: true,//刷新按钮
                queryParams: queryParams,
                // onDblClickRow: function (row,index) {
                //     console.log(index[0])
                //     console.log("双击")
                // },
                onClickRow: function (row, tr) {
                    tr[0].firstElementChild.firstElementChild.click();
                    document.getElementById("toolbar").style.display = ""
                    let values=row.jjfa;
                    if (values.indexOf("报废")!==-1){
                        document.getElementById("toolbar").style.display = ""
                        document.getElementById("delbfbs").innerText=row.sbbh
                        $("#ddh_p").html(row.sbbh)
                        $("#djlx_p").html(row.gsid)
                        $("#id_p").html(row.id)
                    }else {
                        document.getElementById("toolbar").style.display = "none"
                    }
                },
                url: "/sbgl/sbwhb/getdelwhjl/",
                columns: [{
                    radio: true,
                    field: 'check',
                    align: "center"
                },
                    {
                        field: 'no',
                        title: '序号',
                        align: "center",
                        width: 60,
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    },
                    {
                        field: 'gsid',
                        title: '公司编码'
                    },
                    {
                        field: 'whlb',
                        title: '维护类别'
                    },
                    {
                        field: 'whjlbh',
                        title: '设备名称'
                    },
                    {
                        field: 'sbbh',
                        title: '设备编号'
                    },
                    {
                        field: 'gzyy',
                        title: '故障原因'
                    },
                    {
                        field: 'jjfa',
                        title: '解决方案'
                    },
                    {
                        field: 'id',
                        title: 'id号',
                        visible: false,
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var id = index;
                            var result = "";
                            let values=row.jjfa;
                            if (values.indexOf("报废")!==-1){
                                result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"EditViewById('" + row + "','" + id + "')\" title='是否删除报废标识'><span class='glyphicon glyphicon-pencil'></span></a>";
                                result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"DeleteById('" + row + "','" + id + "')\" title='删除'><span class='glyphicon glyphicon-trash'></span></a>";
                            }else {
                                result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"DeleteById('" + row + "','" + id + "')\" title='删除'><span class='glyphicon glyphicon-trash'></span></a>";
                            }
                            return result;
                        }
                    }]
            })
        }
    })
    function queryParams(params) {
        var param = {
            limit: params.limit, // 页面大小
            offset: params.offset, // 页码
            nextPage: params.pageNumber,
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            cxtj: $("#sbbh").val(),
            gsid: $("#pgsid").text(),
            // bfbs: $("#is_bf").val(),
        };
        return param;
    }

    //查询按钮事件
    $('#search_btn').click(function () {
        refresh()
    });

    function refresh() {
        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
        //获取当前是第几页
        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
        $("#_pageNumber").val(pageNumber);
        $("#_pageSize").val(pageSize);
        $('#bootstrap-table').bootstrapTable('refresh', {
            pageNumber: pageNumber,
            pageSize: pageSize,
        });
    }

    function addgsmc() {
        var sbbh = $("#ddh_p").text()
        var gsid = $("#djlx_p").text()
        var ids = $("#id_p").text()
        $.confirm({
            title: '温馨提示',
            content: '确定将设备'+sbbh+'报废标识删除吗？？？',
            buttons: {
                OK: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/sbwhb/delbaof/'+ids+'/'+gsid+'/'+sbbh,
                            method: 'POST',
                        }).done(function (response) {
                            refresh()
                        }).fail(function () {
                        });
                    }
                },
                CANCE: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    }

    function confirm(title,content,ele) {
        $.confirm({
            title: title,
            content: content,
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function(){
                        $(ele).modal('hide');
                    }
                }
            }
        });
    }

    function EditViewById(row, index)  {
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data);
        var gsid =data_json[index].gsid;
        var ids=data_json[index].id;
        var sbbh=data_json[index].sbbh;
        $.confirm({
            title: '温馨提示',
            content: '确定将设备'+sbbh+'报废标识删除吗？？？',
            buttons: {
                OK: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/sbwhb/delbaof/'+ids+'/'+gsid+'/'+sbbh,
                            method: 'POST',
                        }).done(function (response) {
                            refresh()
                        }).fail(function () {
                        });
                    }
                },
                CANCE: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    }

    function DeleteById(row,index) {
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data);
        var id=data_json[index].id;
        var gzyy=data_json[index].gzyy;
        $.confirm({
            title: '维护记录删除',
            content: '您现在的操作是删除维护记录，您确定删除【'+gzyy+'】吗？',
            buttons: {
                确认: function () {
                    $.ajax({
                        url: "/sbgl/sbwhb/remove/" + id,
                        type: 'POST',
                        success: function (result) {
                            if (result != null) {
                                refresh()
                                confirm("温馨提示","解决方案删除成功！！！")
                            }
                        }
                    });
                },
                取消: function () {
                }
            }
        });
    }
</script>
</body>
</html>